//
//  ActivityTableViewCell.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/6/6.
//

#import "ActivityTableViewCell.h"
#import "CommonUtil.h"


@interface ActivityTableViewCell()
@property (strong, nonatomic) UIView * whiteView;
@property (strong, nonatomic) UILabel * tipLabel;

@property (strong, nonatomic) UIView * indexBGView;
@property (strong, nonatomic) UIView * indexView;
@property (strong, nonatomic) UILabel * nunberLabel;
@property (strong, nonatomic) UILabel * tipLabel2;
@property (strong, nonatomic) UIView * lineView;
@property (strong, nonatomic) UIButton * zanBtn;

@end


@implementation ActivityTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:self.whiteView];
        [self.whiteView addSubview:self.tipLabel];
        [self.whiteView addSubview:self.indexBGView];
        [self.indexBGView addSubview:self.indexView];
        [self.whiteView addSubview:self.nunberLabel];
        [self.whiteView addSubview:self.tipLabel2];
        [self.whiteView addSubview:self.lineView];
        [self.whiteView addSubview:self.zanBtn];
    }
    return self;
}

-(void)setModel:(ActivityModel *)model{
    _model = model;
    
    if (model.atLast) {
        self.indexBGView.hidden = YES;
        self.indexView.hidden = YES;
        self.nunberLabel.hidden = YES;
        self.tipLabel.text = @"在线15分钟以上,退出登陆无效";
        [self.zanBtn setTitle:@"去论坛" forState:UIControlStateNormal];
        
        self.tipLabel.top = AD(30);
        self.tipLabel2.top = self.indexBGView.bottom;
        
    }else{
        
        
        NSInteger number1 = model.count;
        NSInteger number2 = model.totalCount;
        

        NSString *text = [NSString stringWithFormat:@"%zd / %zd",number1,number2];
        NSMutableAttributedString *attribut = [[NSMutableAttributedString alloc]initWithString:text];
        NSRange range1 = [text rangeOfString:[NSString stringWithFormat:@"%zd",number1]];
        [attribut addAttribute:NSForegroundColorAttributeName value:RGB(255.0, 142.0, 88.0) range:range1];
        self.nunberLabel.attributedText = attribut;
        
        
        self.tipLabel.text = @"点赞10次不同的帖子";
        self.tipLabel.top = AD(20);
        self.tipLabel2.top = self.indexBGView.bottom + AD(10);
        self.indexBGView.hidden = false;
        self.indexView.hidden = false;
        self.nunberLabel.hidden = false;
        [self.zanBtn setTitle:@"去点赞" forState:UIControlStateNormal];
        NSNumber *c = [NSNumber numberWithInteger:model.count];
        self.indexView.width = (c.floatValue / model.totalCount) * self.indexBGView.width;
    }
    
    
}

- (void)zanBtnClick:(UIButton *)sender{
    NSLog(@"%@",sender.titleLabel.text);
}


-(UIView *)whiteView{
    if (!_whiteView) {
        _whiteView = [[UIView alloc] initWithFrame:CGRectMake(AD(15), 0, SCREEN_WIDTH-AD(30), AD(100))];
        _whiteView.backgroundColor = [UIColor whiteColor];
    }
    return _whiteView;
}

-(UILabel *)tipLabel{
    if (!_tipLabel) {
        _tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(AD(10), AD(20), _whiteView.width-AD(20), AD(25))];
        _tipLabel.textColor = RGB(30, 30, 30);
        _tipLabel.font = [UIFont systemFontOfSize:AD(16)];
        _tipLabel.text = @"点赞10次不同的帖子";
    }
    return _tipLabel;
}

-(UIView *)indexBGView{
    if (!_indexBGView) {
        _indexBGView = [[UIView alloc] initWithFrame:CGRectMake(AD(10), _tipLabel.bottom +AD(5), AD(110), AD(10))];
        _indexBGView.backgroundColor = RGB(225, 225, 225);
        _indexBGView.layer.cornerRadius = AD(5);
        _indexBGView.clipsToBounds = YES;
    }
    return _indexBGView;
}


-(UIView *)indexView{
    if (!_indexView) {
        _indexView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, self.indexBGView.height)];
        _indexView.backgroundColor = RGB(255,76, 47);
        _indexView.layer.cornerRadius = AD(5);
    }
    return _indexView;
}

-(UILabel *)nunberLabel{
    if (!_nunberLabel) {
        _nunberLabel = [[UILabel alloc] initWithFrame:CGRectMake(_indexBGView.right + AD(5), AD(20), AD(80), AD(25))];
        _nunberLabel.textColor = RGB(30, 30, 30);
        _nunberLabel.font = [UIFont systemFontOfSize:AD(14)];
        _nunberLabel.centerY = self.indexBGView.centerY;
    }
    return _nunberLabel;
}

-(UILabel *)tipLabel2{
    if (!_tipLabel2) {
        _tipLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(AD(10), _indexBGView.bottom + AD(10), _whiteView.width-AD(20), AD(20))];
        _tipLabel2.textColor = RGB(255, 142, 88);
        _tipLabel2.font = [UIFont systemFontOfSize:AD(14)];
        _tipLabel2.text = @"完成任务+1朵,VIP可获得2朵";
    }
    return _tipLabel2;
}
-(UIView *)lineView{
    if (!_lineView) {
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, AD(99), self.whiteView.width, AD(1))];
        _lineView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    }
    return _lineView;
}

-(UIButton *)zanBtn{
    if (!_zanBtn) {
        _zanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _zanBtn.backgroundColor = RGB(255, 97, 31);
        [_zanBtn setTitle:@"去点赞" forState:UIControlStateNormal];
        [_zanBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _zanBtn.titleLabel.font = [UIFont systemFontOfSize:AD(15)];
        [_zanBtn addTarget:self action:@selector(zanBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _zanBtn.frame = CGRectMake(0, AD(10), AD(80), AD(35));
        _zanBtn.layer.cornerRadius = _zanBtn.height/2;
        _zanBtn.right = _whiteView.width - AD(10);
        _zanBtn.centerY = self.whiteView.centerY;
    }
    return _zanBtn;
}

@end
